﻿
async function convertToPdf(url) {
    try {
        // 下载网页内容
        const response = await fetch(url);

        const html = await response.text();

        // 准备发送到后端API的数据
        const data = new FormData();
        data.append('htmlContent', html);

        // 调用后端API
        const pdfResponse = await fetch('/api/ToPdf/ConvertHtmlToPdf', {
            method: 'POST',
            body: data
        });
        if (pdfResponse.ok) {
            const pdfData = await pdfResponse.text();
            return pdfData;
        } else {
            throw new Error('Network response was not ok.');
        }
    }
    catch (error) {
        console.error(error);
    }
}
function getCurrentTime() {
    var currentDate = new Date();
    var year = currentDate.getFullYear();
    var month = currentDate.getMonth() + 1;
    var day = currentDate.getDate();
    var hours = currentDate.getHours();
    var minutes = currentDate.getMinutes();
    var seconds = currentDate.getSeconds();

    // 格式化时间为 HH:mm:ss
    var formattedTime = year + "年" + formatTime(month) + "月" + formatTime(day) + "日" + formatTime(hours) + ":" + formatTime(minutes) + ":" + formatTime(seconds);

    return formattedTime;
}

function formatTime(time) {
    // 在个位数前补零
    return time < 10 ? "0" + time : time;
}

function updateCurrentTime() {
    var currentTimeElement = document.getElementById("currentTime");
    currentTimeElement.textContent = getCurrentTime();
}

// 每秒钟更新一次时间
setInterval(updateCurrentTime, 1000);
function togglePDF() {

    var Boli = document.getElementById("Bo");
    var button2 = document.getElementById("Zhan");

    if (Boli.style.display == "") {
        Boli.style.display = "none";
        button2.style.display = "";

    } else {
        Boli.style.display = ""
        button2.style.display = "none";
    }
}
function downloadFileFromBase64(filename, content) {
    var link = document.createElement('a');
    link.href = content;
    link.download = filename;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}
